﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using DnD.ViewModels;
using Microsoft.Phone.Info;

namespace DnD
{
    public partial class GamePage : PhoneApplicationPage
    {
        public GamePage()
        {
            InitializeComponent();



        }



        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            string deckIDString;
            if (NavigationContext.QueryString.TryGetValue("deckID", out deckIDString))
            {
                int deckID;
                if (int.TryParse(deckIDString, out deckID))
                {
                    DataContext = new GameViewModel(deckID, this);
                    ((GameViewModel)DataContext).CardInStoryboard = StoryBoardMoveCardIn;
                    ((GameViewModel)DataContext).CardOutStoryboard = StoryBoardMoveCardOut;
                }

            }

        }


        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            ((GameViewModel)DataContext).clearAppState();
            base.OnBackKeyPress(e);
        }
        

        private void CardItem_ManipulationStarted(object sender, System.Windows.Input.ManipulationStartedEventArgs e)
        {
            ((GameViewModel)DataContext).CardItem_ManipulationStarted(sender, e);
        }

        private void CardItem_ManipulationDelta(object sender, System.Windows.Input.ManipulationDeltaEventArgs e)
        {
            ((GameViewModel)DataContext).CardItem_ManipulationDelta(sender, e);
        }


    }
}